<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>capitalizeEveryWord(所有单词首字母大写转换器)</title>
    <link rel="stylesheet" href="https://www.unpkg.com/ew-message/dist/ew-message.min.css">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
            text-align: center;
        }

        h1 {
            color: #333;
        }

        .container {
            max-width: 600px;
            margin: 0 auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        textarea, input {
            width: 100%;
            font-size: 16px;
            padding: 10px;
            margin-top: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            box-sizing: border-box;
        }

        button {
            padding: 10px 20px;
            margin-top: 15px;
            font-size: 16px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        button:hover {
            background-color: #45a049;
        }

        .output-section {
            margin-top: 20px;
        }

        .result-text {
            height: 100px;
        }
    </style>
</head>
<body>

    <div class="container">
        <h1>标题大写工具</h1>
        <p>输入一些文本，它将把每个单词的首字母大写。</p>

        <textarea id="inputText" placeholder="在这里输入单词文本"></textarea>

        <button onclick="applyCapitalization()">格式化单词（首字母大写）</button>

        <div class="output-section">
            <h3>格式化结果:</h3>
            <textarea id="resultText" class="result-text" readonly placeholder="格式化后的大写单词结果将显示在此处"></textarea>
        </div>

        <div class="output-section">
            <button onclick="copyToClipboard()">复制</button>
            <button onclick="downloadResult()">下载结果</button>
        </div>
    </div>
    <script src="https://www.unpkg.com/ew-message/dist/ew-message.min.js"></script>
    <script>
        const capitalizeEveryWord = str =>
            str.replace(/\b[a-z]/g, w => w.toUpperCase());

        function applyCapitalization() {
            const inputText = document.getElementById("inputText").value;
            const resultText = capitalizeEveryWord(inputText);
            document.getElementById("resultText").value = resultText;
        }

        function copyToClipboard() {
            const resultText = document.getElementById("resultText");
            resultText.select();
            resultText.setSelectionRange(0, 99999); 
            document.execCommand("copy");
            ewMessage("复制结果成功!");
        }

        function downloadResult() {
            const resultText = document.getElementById("resultText").value;
            const blob = new Blob([resultText], { type: "text/plain;charset=utf-8" });
            const link = document.createElement("a");
            link.href = URL.createObjectURL(blob);
            link.download = "formatted_text.txt";
            link.click();
        }
    </script>

</body>
</html>
